package trystero.lib.component.parser;

import java.io.InputStream;
import java.io.InputStreamReader;

import org.json.JSONObject;
import org.json.JSONTokener;
import org.json.JSONArray;

import trystero.lib.component.UserInfo;

public class UserInfoParser
{
   InputStream stream;

   public UserInfoParser(InputStream stream)
   {
      this.stream = stream;
   }

   public UserInfo parse() throws Exception
   {
      JSONTokener t = new JSONTokener(new InputStreamReader(this.stream));
      JSONObject o = new JSONObject(t);
      return this.parse(o);
   }

   public UserInfo parse(JSONObject o) throws Exception
   {
      UserInfo u = new UserInfo();

      u.id((String)o.get("userId"));
      u.name((String)o.get("userName"));
      u.profile((String)o.get("userProfileId"));
      u.email((String)o.get("userEmail"));
      //u.blogger((Boolean)o.get("userEmail"));
      u.signup(((Integer)o.get("signupTimeSec")).longValue());

      return u;
   }
}
